package com.cl.blog.web.manager.examine;

import cn.hutool.core.lang.Assert;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cl.blog.annotation.Login;
import com.cl.blog.common.Const;
import com.cl.blog.common.Result;
import com.cl.blog.entity.BContent;
import com.cl.blog.service.BContentExamineService;
import com.cl.blog.service.BContentService;
import com.cl.blog.util.JwtUtil;
import com.cl.blog.vo.ExamineNoPassVo;
import io.jsonwebtoken.Claims;
import lombok.extern.java.Log;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 付
 * @Date 2024-03-20 16:09
 * @Version 1.0
 * @description 审核管理，包括了文章审核，评论审核
 * @since 1.0
 */
@RestController
@RequestMapping("/admin/examine")
public class ExamineController {

	@Resource
	BContentExamineService bContentExamineService;

	@Resource
	BContentService bContentService;
	@Resource
	JwtUtil jwtUtil;

	/**
	 * 1，3是所有的数据
	 * 传0 查1，2
	 * 传1 查1（未审核）
	 * 传2 查3（未通过）
	 *
	 * @return
	 */
//	@Login(issuer = Const.GRADE_ADMIN)
	@GetMapping("/clist")
	public Result listContent(Integer status) {
		return Result.success(bContentService.selectByStatus(status));
	}

	@PostMapping("/ispass")
//	@Login(issuer = Const.GRADE_ADMIN)
	public Result noPass(@RequestBody ExamineNoPassVo examineNoPassVo, HttpServletRequest request) {
		String token = request.getHeader("token");
		Claims claim = jwtUtil.getClaimByToken(token, Const.GRADE_ADMIN);
		Integer adminId = Integer.valueOf(claim.getSubject());
		if (examineNoPassVo.getId() == 2) {
			Assert.isTrue(examineNoPassVo.getContentStatus() != 3, "抱歉，当前文章已审核");
		}

		return Result.success(bContentExamineService.noPass(examineNoPassVo, adminId));
	}
}
